<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>生成器</title>
	</head>
	<body>
		<script>
			// 生成器其实就是一个特殊函数
			// 异步编程,纯回调函数 node fs ajax mongodb
			// 函数代码分隔符
			function * gen() {
				// console.log('test message.');
				console.log('aaaaaaa');
				yield 'one';
				console.log('bbbbb');
				yield 'two';
				console.log('cccc');
				yield 'three';
				console.log('ddddd');
			}
			let iter = gen();
			console.log(iter);
			console.log(iter.next());
			console.log(iter.next());
			console.log(iter.next());
			console.log(iter.next());
			
			for(let v of gen()) {
				console.log(v);
			}
			
			function * gen2(arg) {
				console.log(arg);
				let one = yield 111;
				console.log(one);
				let two = yield 222;
				console.log(two);
				let three = yield 333;
				console.log(three);
			}
			let iter2 = gen2('AAA');
			console.log(iter2.next());
			console.log(iter2.next('BBB'));
			console.log(iter2.next('CCC'));
			console.log(iter2.next('DDD'));
			
			// 需求 1秒钟后输出111 2秒后输出222 3秒后输出333
			function one() {
				setTimeout(()=>{
					console.log('111');
					
				},1000);
			}
			
			function two() {
				setTimeout(()=>{
					console.log('111');
					
				},2000);
			}
			
			function three() {
				setTimeout(()=>{
					console.log('111');
					
				},3000);
			}
			
		</script>
	</body>
</html>